﻿<%@ Page Title="Inquiry Incoming Transmittal" Language="C#" MasterPageFile="~/eTransmittal.Master"
    AutoEventWireup="true" CodeBehind="InquiryIncoming.aspx.cs" Inherits="POI.eTransmittal.WebApp.InquiryIncoming" %>

<%@ Register Assembly="DevExpress.Web.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxSplitter" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Xpo.v11.2.Web, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Xpo" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxUploadControl" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxCallbackPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxHiddenField" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxCallback" tagprefix="dx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
    <table width="100%">
        <tr>
            <td>
                <dx:ASPxGridView ID="gridTransmittal" ClientInstanceName="gridTransmittal" runat="server"
                    AutoGenerateColumns="False" DataSourceID="xpodsIncoming" KeyFieldName="ID" Width="100%"
                    OnCustomCallback="gridTransmittal_CustomCallback" 
                    onrowdeleted="gridTransmittal_RowDeleted" 
                    oncommandbuttoninitialize="gridTransmittal_CommandButtonInitialize" 
                    oncustombuttoninitialize="gridTransmittal_CustomButtonInitialize">
                    <ClientSideEvents CustomButtonClick="function(s, e) {
	onEdit(s,e);
}" />
                    <Columns>
                        <dx:GridViewDataTextColumn Caption="Log No." FieldName="ID" VisibleIndex="0" SortIndex="0"
                            SortOrder="Descending" Width="20px">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataDateColumn FieldName="ReceivedDate" VisibleIndex="2" 
                            Width="130px">
                            <PropertiesDateEdit DisplayFormatString="dd MMM yyyy  HH:mm:ss" 
                                EditFormatString="dd MMM yyyy">
                            </PropertiesDateEdit>
                        </dx:GridViewDataDateColumn>
                        <dx:GridViewDataTextColumn FieldName="Subject" VisibleIndex="3">
                            <Settings AutoFilterCondition="Contains" />
                            <DataItemTemplate>
                            <%#Eval("UncLink") == "" || Eval("UncLink") == null ? Container.Text : Container.Text + "&nbsp;<img src='images/attachment.png' />"%>
                             <%--   <a href="<%#Container.Text %>" target="_blank">View File</a>--%>
                            </DataItemTemplate>                
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="From" VisibleIndex="4" Width="70px">
                            <Settings AutoFilterCondition="Contains" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="InboxName" VisibleIndex="1" Width="65px" 
                            SortIndex="1" SortOrder="Ascending">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="AttnNames" VisibleIndex="5" Width="180px" 
                            Caption="Attn">
                            <Settings AutoFilterCondition="Contains" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="Status" VisibleIndex="7" Width="40px">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewCommandColumn Caption=" " VisibleIndex="10" Width="70px">
                            <DeleteButton Visible="True">
                            </DeleteButton>
                            <ClearFilterButton Visible="True">
                            </ClearFilterButton>
                            <CustomButtons>
                                <dx:GridViewCommandColumnCustomButton ID="custEdit" Text="View">
                                </dx:GridViewCommandColumnCustomButton>
                            </CustomButtons>
                        </dx:GridViewCommandColumn>
                    </Columns>
                    <SettingsBehavior ConfirmDelete="True" />
                    <Settings ShowFilterRow="True" ShowFilterRowMenu="True" ShowGroupPanel="True" />
                    <SettingsText ConfirmDelete="Are you sure to delete this row ?" />
                </dx:ASPxGridView>
                <dx:XpoDataSource ID="xpodsIncoming" runat="server" TypeName="POI.eTransmittal.Enitity.IncomingTransmittal">
                </dx:XpoDataSource>
                <dx:XpoDataSource ID="xpoDsInbox" runat="server" TypeName="POI.eTransmittal.Enitity.Inbox">
                </dx:XpoDataSource>
                <dx:XpoDataSource ID="xpodsTransUser" runat="server" 
                    TypeName="POI.eTransmittal.Enitity.TransmittalUser">
                </dx:XpoDataSource>
                <dx:XpoDataSource ID="xpoDsContact" runat="server" Criteria="[Internal] = False"
                    TypeName="POI.eTransmittal.Enitity.Contact">
                </dx:XpoDataSource>
                <dx:ASPxCallback ID="clbCancel" runat="server" ClientInstanceName="clbCancel" 
                    oncallback="clbCancel_Callback">
                    <ClientSideEvents CallbackComplete="function(s, e) {
	OnUploadCanceled(e);
}" />
                </dx:ASPxCallback>
              <dx:ASPxPopupControl ID="popUser" 
        runat="server" HeaderText="Select User" Width="300px" 
        PopupHorizontalAlign="RightSides" PopupVerticalAlign="Below" 
                    ClientInstanceName="popUser" AllowDragging="True" MinWidth="300px" 
                    RenderIFrameForPopupElements="True">
                                            <ContentCollection>
<dx:PopupControlContentControl ID="PopupControlContentControl1" runat="server" SupportsDisabledAttribute="True">
<table width="100%"><tr><td>
    <dx:ASPxGridView ID="grdEmployee" runat="server" AutoGenerateColumns="False" 
        Width="100%" ClientInstanceName="grdEmployee" 
        OnCustomCallback="grdEmployee_CustomCallback" 
        DataSourceID="xpodsTransUser" KeyFieldName="UserID">
        <ClientSideEvents EndCallback="function(s, e) {
	onLoadEmployeeDone();
}" />
        <Columns>
            <dx:GridViewCommandColumn Caption=" " ShowInCustomizationForm="True" 
                VisibleIndex="0" ShowSelectCheckbox="True" Width="15px">
            </dx:GridViewCommandColumn>
            <dx:GridViewDataTextColumn FieldName="Name" ShowInCustomizationForm="True" 
                VisibleIndex="2">
            </dx:GridViewDataTextColumn>
        </Columns>
        <SettingsPager PageSize="5" NumericButtonCount="1">
        </SettingsPager>
        <Settings ShowFilterRow="True" />
    </dx:ASPxGridView></td></tr>
      
            <tr>
                <td>
                    
                    <dx:ASPxButton ID="btnuserSave" runat="server" AutoPostBack="False" Text="Ok" 
                        Width="100%">
                        <ClientSideEvents Click="function(s, e) {
	OnSelectEmployeeDone();
}" />
                    </dx:ASPxButton>
                    
                </td>
            </tr>
     
    </table>
   
  
    
    
                                                </dx:PopupControlContentControl>
</ContentCollection>
    </dx:ASPxPopupControl>
                <dx:ASPxPopupControl ID="popEdit" runat="server" Width="900px" HeaderText="Edit Transmittal"
                    ClientInstanceName="popEdit" PopupHorizontalAlign="WindowCenter" 
                    PopupVerticalAlign="WindowCenter" Modal="True" AllowDragging="True" 
                    Height="600px">
                    <ClientSideEvents Shown="function(s, e) {
	clbPanelEdit.PerformCallback('load;' + transIDtoShow);
}" />
<ClientSideEvents Shown="function(s, e) {
	clbPanelEdit.PerformCallback(&#39;load;&#39; + transIDtoShow);
}"></ClientSideEvents>
                    <ContentCollection>
                        <dx:PopupControlContentControl runat="server" SupportsDisabledAttribute="True">
                            
                            <table style="width:100%;">
                            <tr>
                                <td><dx:ASPxCallbackPanel ID="clbPanelEdit" runat="server" Width="100%" 
                                ClientInstanceName="clbPanelEdit" OnCallback="clbPanelEdit_Callback">

<ClientSideEvents EndCallback="function(s, e) {
	handlePopEditInfo();
}"></ClientSideEvents>
                                <PanelCollection>
<dx:PanelContent ID="PanelContent1" runat="server">
<table width="100%">
                                <tr>
                                    <td valign="top">
                                    <table width="100%" style="height: 100%">
                                            <tr>
                                                <td width="60px">
                                                    Subject
                                                </td>
                                                <td colspan="3" bgcolor="#CCCCCC">
                                                    <dx:ASPxTextBox ID="txtPopSubject" runat="server" Width="100%" ClientInstanceName="txtPopSubject">
                                                    </dx:ASPxTextBox>
                                                </td>
                                                 <td>
                                                     &nbsp;</td>
                                                <td>
                                                    No
                                                </td>
                                                <td bgcolor="#CCCCCC" style="padding-left: 5px">
                                                    <dx:ASPxLabel ID="lblPopNo" runat="server" Text="(auto generated)">
                                                    </dx:ASPxLabel>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="100px">
                                                    Received Date
                                                </td>
                                                <td bgcolor="#CCCCCC">
                                                    <dx:ASPxDateEdit ID="dtePopReceivedDate" runat="server" 
                                                        ClientInstanceName="dteReceivedDate" DisplayFormatString="dd MMM yyyy  HH:mm:ss" 
                                                        EditFormat="Custom" EditFormatString="dd MMM yyyy  HH:mm:ss" 
                                                        UseMaskBehavior="True">
                                                    </dx:ASPxDateEdit>
                                                </td>
                                                <td>
                                                    &nbsp;</td>
                                                <td>
                                                    &nbsp;</td>
                                                  <td>
                                                      &nbsp;</td>
                                                <td width="50px">
                                                    Attn
                                                </td>
                                                <td bgcolor="#CCCCCC">
                                                    <dx:ASPxButtonEdit ID="btePopAttn" runat="server" Width="100%">
                                                        <ClientSideEvents ButtonClick="function(s, e) {
	ShowSelectEmployee(s, 'Attn');
}" />                                                        <Buttons>
                                                            <dx:EditButton>
                                                            </dx:EditButton>
                                                        </Buttons>
                                                    </dx:ASPxButtonEdit>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    Inbox
                                                </td>
                                                <td width="90px" bgcolor="#CCCCCC">
                                                    <dx:ASPxComboBox ID="cboPopInbox" runat="server" DataSourceID="xpodsInbox" 
                                                        TextField="Name" ValueField="Name" ClientInstanceName="cboPopInbox">
                                                    </dx:ASPxComboBox>
                                                </td>
                                                <td width="48px">
                                                    From </td>
                                                <td width="90px" bgcolor="#CCCCCC">
                                                    <dx:ASPxComboBox ID="cboPopFrom" runat="server" ClientInstanceName="cboPopFrom" 
                                                        DataSourceID="xpoDsContact" TextField="Name" ValueField="ID">
                                                    </dx:ASPxComboBox>
                                                </td>
                                                <td width="42px">
                                                    </td>
                                                <td>
                                                    Cc
                                                </td>
                                                <td bgcolor="#CCCCCC">
                                                    <dx:ASPxButtonEdit ID="btePopCc" runat="server" Width="100%">
                                                        <ClientSideEvents ButtonClick="function(s, e) {
	ShowSelectEmployee(s, 'Cc');
}" />
                                                        <Buttons>
                                                            <dx:EditButton>
                                                            </dx:EditButton>
                                                        </Buttons>
                                                    </dx:ASPxButtonEdit>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td height="27px" valign="top">
                                                    Remarks
                                                </td>
                                                <td colspan="3" height="27px" valign="top" bgcolor="#CCCCCC">
                                                    <dx:ASPxTextBox ID="txtPopRemarks" runat="server" Width="100%">
                                                    </dx:ASPxTextBox>
                                                </td>
                                                 <td valign="top">
                                                     &nbsp;</td>
                                                <td>
                                                    Doc
                                                </td>
                                                <td width="320" bgcolor="#CCCCCC">
                                                    <table cellpadding="0" cellspacing="0" style="width:100%;">
                                                        <tr>
                                                            <td valign="top" align="center">
                                                                <dx:ASPxButton ID="btnChange" runat="server" AutoPostBack="False" 
                                                                    ClientInstanceName="btnChange" Width="280px">
                                                                    <ClientSideEvents Click="function(s, e) {
if(s.GetText() != 'Cancel')
{
	s.SetText('Cancel');
	toggleUpload('change');
	//lblFile.SetClientVisible(false);	
}
else
{
	//s.SetText('Change File');
	clbCancel.PerformCallback(transIDtoShow);
	//lblFile.SetClientVisible(true);
}
}" />
                                                                </dx:ASPxButton>
                                                                <dx:ASPxUploadControl ID="upcPopDoc" runat="server" 
                                                                    ClientInstanceName="upcPopDoc" ClientVisible="False" 
                                                                    OnFileUploadComplete="upcPopDoc_FileUploadComplete1" 
                                                                    ShowClearFileSelectionButton="False" ShowUploadButton="True" Width="280px">
                                                                    <ValidationSettings MultiSelectionErrorText="Attention! 

The following {0} files are invalid because they exceed the allowed file size ({1}) or their extensions are not allowed. These files have been removed from selection, so they will not be uploaded. 

{2}">
                                                                    </ValidationSettings>
                                                                    <ClientSideEvents FileUploadComplete="function(s, e) {
	onUploadComplete(e);
}" />
                                                                </dx:ASPxUploadControl>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                    
                                                  
                                                    
                                                </td>
                                            </tr>
                                        </table>
                                       
                                    </td>
                                   
                                </tr>
                                <tr>
                                    <td align="right">
                                        &nbsp;</td>
                                </tr>
                                
                                <tr>
                                    <td align="right" bgcolor="#999999">
                                        <table>
                                            <tr>
                                                <td>
                                                    <dx:ASPxButton ID="btnDistribute" runat="server" AutoPostBack="False" 
                                                        Text="Send">
                                                        <ClientSideEvents Click="function(s, e) {
	onPopDistribute();
}" />
                                                    </dx:ASPxButton>
                                                </td>
                                                <td>
                                                    <dx:ASPxButton ID="btnSave" runat="server" AutoPostBack="False" Text="Save">
                                                        <ClientSideEvents Click="function(s, e) {
	onPopSave();
}" />
                                                    </dx:ASPxButton>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                
                            </table>
                              <dx:ASPxHiddenField ID="hfField" runat="server" 
        ClientInstanceName="hfField" OnCustomCallback="hfField_CustomCallback">
                                                    <ClientSideEvents EndCallback="function(s, e) {
	onLinkUpdated(s,e);
}" />
                                                    </dx:ASPxHiddenField>   
                                    </dx:PanelContent>
</PanelCollection>
                            </dx:ASPxCallbackPanel></td>
                            </tr>
                            <tr>
                                <td><iframe id="frDoc" width="100%" height="400" style="z-index: 0" ></iframe></td>
                            </tr>
                            </table>
                        </dx:PopupControlContentControl>
                    </ContentCollection>
                </dx:ASPxPopupControl>
            </td>
        </tr>
    </table>
<script type="text/javascript">
    var allowExtensions = ['msg', 'pdf'];
    function OnTextChanged(uploadControl) {
        if (!isValidFileName(uploadControl.GetText())) {
            uploadControl.ClearText();
            alert("File extension isn't allowed");
        }
    }
    function isValidFileName(fileName) {
        var fileParts = fileName.split(".");
        var fileExtension = fileParts[fileParts.length - 1];
        return arrayIndexOf(allowExtensions, fileExtension) != -1;
    }
    function arrayIndexOf(array, element) {
        for (var i = 0; i < array.length; i++) {
            if (array[i] == element)
                return i;
        }
        return -1;
    }

    function onEdit(s, e) {
        s.GetRowValues(e.visibleIndex, "ID;Subject;From;ReceivedDate;InboxName;Remarks;OriginalFileName;Attn;Cc;FaxFileLink", onGetIdCompleted);
    }
    var transIDtoShow = -1;
    function onGetIdCompleted(values) {
        transIDtoShow = values[0];

        popEdit.Show();
    }
    function onPopSave() {
        clbPanelEdit.PerformCallback('save;' + transIDtoShow);
    }
    function onPopDistribute() {
        clbPanelEdit.PerformCallback('distribute;' + transIDtoShow);
    }
    function onPopCancel() {
        popEdit.Hide();
        clbPanelEdit.PerformCallback('cancel;' + transIDtoShow);
    }
    function handlePopEditInfo() {
        var isErr = hfField.Get('error');
        var isinfo = hfField.Get('info');
        var link = hfField.Get('uncLink');

        if (isErr != null || isErr != undefined) {
            ShowErrorMessage(hfField.Get('error'));
            hfField.Clear();
        }
        else if (isinfo != null || isinfo != undefined) {
            
            ShowStatusMessage(hfField.Get('info'));
            popEdit.Hide();
            hfField.Clear();
            gridTransmittal.PerformCallback();
        }
        else if (link != null || link != undefined) {

            var frame = document.getElementById('frDoc');
            //alert(link);
            frame.src = link;          
        }


    }
    function OnSelectEmployee(s, e) {
        var idx = e.visibleIndex;
        s.GetRowValues(idx, "mail;Name", onGetEmployee);
    }
    var txtTowrite = '';
    var txtctr;
    var contactSuccess = true;
    var activeHfType = '';
    var emplRowsSelected = false;

    function ShowSelectEmployee(s, type, mode) {
        
        txtctr = s;
        activeHfType = type;
        emplRowsSelected = false;

        grdEmployee.PerformCallback('bind;' + mode);
        popUser.ShowAtElement(s.GetMainElement());
    }
    function OnSelectEmployeeDone() {
        grdEmployee.GetSelectedFieldValues('UserID;Name', OnGetValues);
    }

    function OnGetValues(results) {
        if (results.length == 0)
            return;

        var value = '';
        var names = '';

        for (i = 0; i < results.length; i++) {
            value += results[i][0] + ';';

            names += names == '' ? '':', ';
            names += results[i][1];
        }

        txtctr.SetText(names);
        if (hfField.Contains(activeHfType))
            hfField.Set(activeHfType, value);
        else
            hfField.Add(activeHfType, value);

        popUser.Hide();
    }
    function toggleUpload(s) {
        var text = s;
        switch (text) {
            case 'change':
                /*var dv = document.getElementById('divReadDoc');
                dv.style.display = 'none';*/
                upcPopDoc.SetClientVisible(true);
                break;
            case 'view':
                /*var dv = document.getElementById('divReadDoc');
                dv.style.display = 'block';*/
                upcPopDoc.SetClientVisible(false);

                break;


        }
    }
    function onUploadComplete(e) {
        toggleUpload('view');
        //lblFile.SetText(e.callbackData);
        btnChange.SetText(e.callbackData);
        hfField.PerformCallback();
    }
    function ClearEntry() {
        dteStartDate.SetText('');
        dteEndDate.SetText('');
        cboInbox.SetText('');
        cboStatus.SetSelectedIndex(0);
        cboFrom.SetText('');
        //  gridTransmittal.PerformCallback();
        //cboFrom
    }
    function OnUploadCanceled(e) {
        //lblFile.SetText(e.result);
        btnChange.SetText(e.result);
        toggleUpload('view');
        hfField.PerformCallback('cancel;' + transIDtoShow);
    }
function onLoadEmployeeDone()
    {
        if ((activeHfType != '') && !emplRowsSelected) {
            if (hfField.Contains(activeHfType)) {
                //alert(activeHfType);
                var employees = hfField.Get(activeHfType).split(';');

                grdEmployee.SelectRowsByKey(employees, true);

                emplRowsSelected = true;
            }
        }
    }
  function onLinkUpdated(s, e) {
    var link = hfField.Get('uncLink');

       
         if (link != null || link != undefined) {

            var frame = document.getElementById('frDoc');
            //alert(link);
            frame.src = link;
        }
    }

</script>
</asp:Content>
